package leetcode_900;

import java.util.HashSet;
import java.util.Set;

/**
 *@author 周杨
 *UniqueMorseCodeWords_804 每个小写字母都代表一种摩斯编码 问一个字典里的单词对应多少不同的摩斯密码
 *describe:用Map AC 53%
 *2018年10月25日 下午6:24:49
 */
public class UniqueMorseCodeWords_804 {
	public int uniqueMorseRepresentations(String[] words) {
        String[] hash=new String[] {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",
        		".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
        Set<String>set=new HashSet<String>();
        for(String word:words) {
        	StringBuilder sb=new StringBuilder();
        	char []chars=word.toCharArray();
        	for(int i=0;i<chars.length;++i) {
        		sb.append(hash[chars[i]-'a']);
        	}
        	set.add(sb.toString());
        }
        return set.size();
    }
}
